package com.volunteer.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.volunteer.common.R;
import com.volunteer.entity.ActivityType;
import com.volunteer.service.ActivityTypeService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/admin/activityType")
@AllArgsConstructor
public class AdminActivityTypeController {
    private final ActivityTypeService activityTypeService;

    // 获取所有类型
    @GetMapping("/list")
    public R<List<ActivityType>> list() {
        List<ActivityType> list = activityTypeService.list(new LambdaQueryWrapper<ActivityType>().orderByAsc(ActivityType::getSort));
        return R.ok(list);
    }

    // 新增类型
    @PostMapping("/add")
    public R<String> add(@RequestBody ActivityType type) {
        boolean success = activityTypeService.save(type);
        return success ? R.ok("新增成功") : R.fail("新增失败");
    }

    // 更新类型
    @PostMapping("/update")
    public R<String> update(@RequestBody ActivityType type) {
        boolean success = activityTypeService.updateById(type);
        return success ? R.ok("更新成功") : R.fail("更新失败");
    }

    // 删除类型
    @DeleteMapping("/delete/{id}")
    public R<String> delete(@PathVariable Long id) {
        boolean success = activityTypeService.removeById(id);
        return success ? R.ok("删除成功") : R.fail("删除失败");
    }
} 